<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/17
 * Time: 15:35
 */
class Dbfactory{
    static private $_driver = array();

    private function __construct(){}

    static public function getDrive(){
        $database = C('DB_DATABASE');
        if(isset(self::$_driver[$database])){
            //如果之前创建过链接就直接返回
            return self::$_driver[$database];
        }else{
            //如果是第一次创建就创建配置项里的数据库引擎
            $engine = 'Db'.C('DB_ENGINE');
            $db = new $engine;
            //链接数据库
            $db->connect();
            return self::$_driver[$database] = $db;
        }
    }
}